<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\map\controller;

class Index extends \app\ApiRest
{
    protected $model;
    protected $coach_model;
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->model = new \app\massage\model\Service();
        $this->coach_model = new \app\massage\model\Coach();
    }
    public function coachList()
    {
        $input = $this->_param;
        $shield_coach = $this->coach_model->getShieldCoach($this->getUserId());
        if(!empty($input["service_time"])) {
            $working_coach = $this->coach_model->getWorkingCoach($this->_uniacid, $input["service_time"]);
            $cannot = \app\massage\model\CoachTimeList::getCannotCoach($this->_uniacid, $input["service_time"]);
            $working_coach = array_merge($working_coach, $cannot);
            $shield_coach = array_merge($working_coach, $shield_coach);
        }
        if(!empty($input["cate_id"])) {
            $cate_model = new \app\massage\model\CateConnect();
            $service_model = new \app\massage\model\ServiceCoach();
            $id = $cate_model->where(["cate_id" => $input["cate_id"]])->column("service_id");
            $coach_id = $service_model->where("ser_id", "in", $id)->column("coach_id");
            $dis[] = ["id", "in", $coach_id];
        }
        $dis[] = ["id", "not in", $shield_coach];
        $dis[] = ["uniacid", "=", $this->_uniacid];
        $dis[] = ["status", "=", 2];
        $dis[] = ["auth_status", "=", 2];
        $dis[] = ["is_work", "=", 1];
        if(!empty($input["coach_name"])) {
            $dis[] = ["coach_name", "like", "%" . $input["coach_name"] . "%"];
        }
        $lat = !empty($input["lat"]) ? $input["lat"] : 0;
        $lng = !empty($input["lng"]) ? $input["lng"] : 0;
        if(!empty($input["city_id"])) {
            $dis[] = ["city_id", "=", $input["city_id"]];
        }
        if(isset($input["sex"])) {
            $dis[] = ["sex", "=", $input["sex"]];
        }
        if(!empty($input["work_time_start"]) && !empty($input["work_time_end"])) {
            $dis[] = ["work_time", "between", $input["work_time_start"] . "," . $input["work_time_end"]];
        }
        if($this->is_app == 0 && getConfigSetting($this->_uniacid, "shield_massage") == 1) {
            $dis[] = ["industry_type", "<>", 1];
        }
        $distance = !empty($input["distance"]) ? $input["distance"] : 100000;
        $alh = "ACOS(SIN((" . $lat . " * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS((" . $lat . " * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS((" . $lng . " * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6378.137*1000 as distance";
        $data = $this->coach_model->mapCoachList($dis, $alh, $distance);
        return $this->success($data);
    }
}

?>